
using System;
using System.Collections;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
 // ERROR: Not supported in C#: OptionDeclaration
namespace NCS_CS
{
	internal partial class FrmOpenSample : System.Windows.Forms.Form
	{
		System.DateTime d1;
		System.DateTime d2;
        //public int sid;
        //public int sampleid;
		public bool reCalc;
        //public int mconfirm;
		string sCondition;

		string cmdtxt;
		private void Command5_Click(System.Object eventSender, System.EventArgs eventArgs)
		{
			string s = null;
			string s1 = null;
			string s2 = null;
			string user1_mname = null;
			user1_mname = "general";
			s = "SELECT * FROM sample ";
			sCondition = " where  cuser='" + user1_mname + "'";
			if (Check1.CheckState == CheckState.Checked ) {
				MdateRange1.getRange(ref d1, ref d2);
				s1 = string.Format("{0:yyyy-MM-dd HH:mm:ss}", d1);
				//(d1, "yyyy-MM-dd HH:mm:ss") 'String.Format("0:F4",x)
				s2 = string.Format("{0:yyyy-MM-dd HH:mm:ss}", d2);
				//Format(d2, "yyyy-MM-dd HH:mm:ss")
				sCondition = sCondition + " and ";
				sCondition = sCondition + "mdate between ";
				sCondition = sCondition + "cdate('" + s1 + "')";
				sCondition = sCondition + " and ";
				sCondition = sCondition + "cdate('" + s2 + "')";
			}
            if (Check2.CheckState == CheckState.Checked)
            {
				sCondition = sCondition + " and ";
				sCondition = sCondition + "cname like ";
				sCondition = sCondition + "'" + MsqlQ1.getText() + "'";
			}
			//s = s + " AND ID IN(SELECT SAMPLEID FROM VOLTNEW)"
			s = s + sCondition;
			cmdtxt = s + " order by mdate";
			refreshOpenSample();
		}


		//    Private Sub DataGrid1_ScrollEvent(ByVal eventSender As System.Object, ByVal eventArgs As AxMSDataGridLib.DDataGridEvents_ScrollEvent) Handles DataGrid1.ScrollEvent
		//        '
		//    End Sub

		//	Private Sub DataGrid1_SelChange(ByVal eventSender As System.Object, ByVal eventArgs As AxMSDataGridLib.DDataGridEvents_SelChangeEvent) Handles DataGrid1.SelChange
		//        ''
		//        '  'debug.print DataGrid1.Bookmark
		//        '  'debug.print "selchange"

		//    End Sub

		//    Private Sub DataGrid1_Validating(ByVal eventSender As System.Object, ByVal eventArgs As System.ComponentModel.CancelEventArgs) Handles DataGrid1.Validating
		//        Dim Cancel As Boolean = eventArgs.Cancel
		//        ''
		//        eventArgs.Cancel = Cancel
		//    End Sub

		//	'UPGRADE_WARNING: Form event FrmOpenSample.Activate has a new behavior. Click for more: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
		//	Private Sub FrmOpenSample_Activated(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Activated
		//		' 'debug.print "active"
		//		mconfirm = 0
		//	End Sub

		//	'UPGRADE_NOTE: Form_Initialize was upgraded to Form_Initialize_Renamed. Click for more: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
		//	Private Sub Form_Initialize_Renamed()

		//		'DataGrid1.Columns[2).NumberFormat = "0.00000" + Chr(34) + "%" + Chr(34) '0 to max-1
		//		'DataGrid1.Columns[3).NumberFormat = "0.00000" + Chr(34) + "%" + Chr(34)
		//		'If Option1.value = True Then
		//		' genIdsBySession 'max session
		//		'Else
		//		' genIdsByMax
		//		'End If
		//		' refreshOri
		//		' refreshRpt
		//	End Sub

		//	Private Sub FrmOpenSample_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		//		'UPGRADE_ISSUE: Global method LoadResPicture was not upgraded. Click for more: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="6B85A2A7-FE9F-4FBE-AA0C-CF11AC86A305"'
		//        'Me.Icon = VB6.LoadResPicture("ncscs", VB6.LoadResConstants.ResIcon)
		//		mconfirm = False
		//		Command5_Click(Command5, New System.EventArgs())
		//		dGridi1 = New DGridI2
		//		dGridi1.setDatagrid(DataGrid1)
		//		reCalc = False
		//	End Sub

		//	Private Sub FrmOpenSample_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
		//		'UPGRADE_NOTE: Object dGridi1 may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		//		dGridi1 = Nothing
		//	End Sub

		//    Private Sub MdateRange1_change(ByVal Sender As System.Object, ByVal e As MdateRange2.changeEventArgs) Handles MdateRange1.change
		//        Dim d1 As Date = e.d1
		//        Dim d2 As Date = e.d2
		//        Check1.CheckState = System.Windows.Forms.CheckState.Checked
		//        Text1.Text = Format(d1, "yyyy-MM-dd hh-mm-ss") + Format(d2, "yyyy-MM-dd hh-mm-ss")
		//    End Sub


		//	Private Sub MSQLQ1_change(ByVal Sender As System.Object, ByVal e As System.EventArgs) Handles MSQLQ1.change
		//		Check2.CheckState = System.Windows.Forms.CheckState.Checked
		//	End Sub

		public void refreshOpenSample()
		{
			IList o = null;
			o = ModMain.getsession().CreateSQLQuery(cmdtxt).AddEntity(typeof(NCS.sample)).List();
            SortableBindingList2<NCS.sample> samples = new SortableBindingList2<NCS.sample>();
            foreach (NCS.sample one in o)
            {
                samples.Add(one);
            }
			if (o.Count < 1)
				return;
			DataGrid1.DataSource = null;
            DataGrid1.DataSource = samples;
            DataGrid1.Columns["mdate"].HeaderText = "分析时间";
            DataGrid1.Columns["name"].HeaderText = "样品名称";
            DataGrid1.Columns["c"].DefaultCellStyle.Format = "0.00000";
            DataGrid1.Columns["c"].HeaderText = "O%";
            DataGrid1.Columns["anaxuhao"].HeaderText = "序号";
            DataGrid1.Columns["s"].DefaultCellStyle.Format = "0.00000";
            DataGrid1.Columns["s"].HeaderText = "N%";
            DataGrid1.Columns["carea"].DefaultCellStyle.Format = "0.0";
            DataGrid1.Columns["cArea"].HeaderText = "O面积";
            DataGrid1.Columns["sarea"].DefaultCellStyle.Format = "0.0";
            DataGrid1.Columns["sArea"].HeaderText = "N面积";
            //DataGrid1.Columns["weight").NumberFormat = "0.0000g"
            DataGrid1.Columns["weight"].HeaderText = "质量";
            DataGrid1.Columns["sIndex"].Visible = false;
            DataGrid1.Columns["sIndex2"].Visible = false;
            DataGrid1.Columns["cIndex"].Visible = false;
            DataGrid1.Columns["cIndex2"].Visible = false;
            DataGrid1.Columns["sInt"].Visible = false;
            DataGrid1.Columns["sessionid"].Visible = false;
            DataGrid1.Columns["cInt"].Visible = false;
            DataGrid1.Columns["isHc"].Visible = false;
            DataGrid1.Columns["isHs"].Visible = false;
            DataGrid1.Columns["method"].Visible = false;
            DataGrid1.Columns["methodid"].Visible = false;
            DataGrid1.Columns["user"].Visible = false;

		}

		private void FrmOpenSample_Load(object sender, System.EventArgs e)
		{
			Command5_Click(null, null);
			//refreshOpenSample()
		}

		private void Command2_Click(System.Object sender, System.EventArgs e)
		{
			this.Hide();
		}

		private void Command3_Click(System.Object sender, System.EventArgs e)
		{
			this.DataGrid1.SelectAll();
		}


		private void Command1_Click(System.Object sender, System.EventArgs e)
		{
			//If Not checkuser() Then Exit Sub
			if (this.DataGrid1.Rows.Count < 1) {
				return;
			}
            DialogResult v = default(DialogResult);
			v = MessageBox.Show(this,"此处快速删除数据,确实删除？","",MessageBoxButtons.YesNo );
            if (v == DialogResult.Yes )
            {
                ModMain.gDb.execute("delete * from tmpid");
                ModMain.gDb.execute("insert into tmpid select distinct id  as sampleid from sample " + sCondition);
                ModMain.gDb.execute("delete * from sample where id in (select sampleid as id from tmpid)");
                //gDb.execute("delete * from voltnew where sampleid in (select * from tmpid)")
                ModMain.gDb.execute("delete * from tmpid ");
                this.refreshOpenSample();
            }
		}

		private void Check3_CheckedChanged(System.Object sender, System.EventArgs e)
		{
            if (Check3.CheckState == CheckState.Checked)
                reCalc = true;
			if (reCalc) {
				Check3.ForeColor = System.Drawing.Color.FromArgb(255, 0, 0);
			} else {
				Check3.ForeColor = System.Drawing.Color.FromArgb (0, 0, 0);
			}
		}

       
	}
}
